package com.example.dzbsh.service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import com.alibaba.fastjson.JSONObject;
import com.example.dzbsh.dao.*;
import com.example.dzbsh.model.*;
import com.example.dzbsh.util.JsonResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.example.dzbsh.util.CreateJSON;
import com.example.dzbsh.util.MD5;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;

@Service
public class DaoruService {

	@Value("${userfilepath}")
    String USERFILEPATH;

    @Resource
    RenyuanMapper ddRenyuanMapper;

    @Resource
    JingshangQingkuangMapper ddJingshangMapper;

    @Resource
    JiashuMapper ddJiashuMapper;

    @Resource
    JiashuService ddJiashuService;

    @Resource
    RenyuanService ddRenyuanService;

    @Resource
    JingshangQingkuangService ddJingshangqingkuangService;

    @Resource
    DeptService ddDeptService;

    @Resource
    CaozuojiluService mmCaozuojiluService;

    @Resource
    ZhenbieQingkuangService ddZhenbieService;

    @Resource
    GuifanluoshiQingkuangMapper ddGuifanMapper;

    @Resource
    FujianService ddFujianService;


    // 导入人员及家属经商情况新版
    @Transactional
    public JsonResult<?> DaoruJingshangQingkuang(String ppDeptId, String ppFileLujing) throws ParseException {

        String userfilepath = USERFILEPATH;
        String mmWenjian = ppFileLujing.split("userfiles")[1];
        userfilepath=userfilepath+mmWenjian;

        List<Dept> mmGuanliDeptList = ddDeptService.findAll();    // 获得管理员端的单位信息集合

        // 将管理端单位id和机构名称码 对应存储
        Map<String, String> mmDeptMap = new HashMap<>();
        for(int a=0;a<mmGuanliDeptList.size();a++){
            mmDeptMap.put(mmGuanliDeptList.get(a).getJigoumingchengma(),mmGuanliDeptList.get(a).getDeptid());
        }

        String Json = CreateJSON.readJsonFile(userfilepath);
        JSONObject mmObjectJson = JSONObject.parseObject(Json);
        Map<String, Object> mmDaoruMap =  (Map<String, Object>)mmObjectJson;
        String mmDaoruDeptId = "";

        // 获得单位List 将这些单位的干部 家属 经商信息删除。
        List<Map<String,Object>> mmDeptList = mmDaoruMap.get("DEPTLIST")==null? null:(List<Map<String,Object>>) mmDaoruMap.get("DEPTLIST");
        // 获取所有删除的数据条数
        int mmShanchuRenyuan = 0; int mmShanchuJiashu = 0;int mmShanchuJingshang = 0;

        for(int b = 0;b < mmDeptList.size();b++) {
            String mmDeptId = mmDeptList.get(b).get("DEPTID") == null ? "" : mmDeptList.get(b).get("DEPTID").toString();
            // 将该单位的经商数据删除。
            List<String> mmRenyuanIdList = ddRenyuanMapper.selectRenyuanIdByDeptId(mmDeptId);
            for (int a = 0; a < mmRenyuanIdList.size(); a++) {
                //循环删除该单位的所有数据
                Map<String,Object> mmDelete = deleteAllRenyuanByRenyuanId(mmRenyuanIdList.get(a));
                // 获得每个单位删除的数据数量
                int mmRenyuan = mmDelete.get("deleteRenyuan")== null ? 0 :Integer.parseInt(mmDelete.get("deleteRenyuan").toString());
                int mmJiashu = mmDelete.get("deleteJiashu")== null ? 0 :Integer.parseInt(mmDelete.get("deleteJiashu").toString());
                int mmJingshang = mmDelete.get("deleteJingshang")== null ? 0 :Integer.parseInt(mmDelete.get("deleteJingshang").toString());
                mmShanchuRenyuan = mmShanchuRenyuan+mmRenyuan;
                mmShanchuJiashu = mmShanchuJiashu+mmJiashu;
                mmShanchuJingshang = mmShanchuJingshang +mmJingshang;
            }
        }

        // 获得所有人员id
        List<String> mmRenyuanidList = ddRenyuanMapper.selectRenyuanIdList();

        // 获得人员List
        List<Map<String,Object>> JingshangRenyuanList = mmDaoruMap.get("RENYUANLIST")==null? null:(List<Map<String,Object>>) mmDaoruMap.get("RENYUANLIST");
        // 获得家属List
        List<Map<String,Object>> JiashuList = mmDaoruMap.get("JIASHULIST")==null? null:(List<Map<String,Object>>) mmDaoruMap.get("JIASHULIST");
        // 获得经商List
        List<Map<String,Object>> JingshangList = mmDaoruMap.get("JINGSHANGLIST")==null? null:(List<Map<String,Object>>) mmDaoruMap.get("JINGSHANGLIST");

        int AddRenyuanNum = JingshangRenyuanList.size();
        int AddJiashuNum = JiashuList.size();
        int AddJingshangNum = JingshangList.size();

        // 循环人员集合
        for(int i=0;i<JingshangRenyuanList.size();i++){
            Map<String,Object> mmRenyuan = JingshangRenyuanList.get(i);
            // 获得当前人员id 及证件号码
            String mmZhengjainhaoma = mmRenyuan.get("ZHENGJIANHAOMA")==null?"":mmRenyuan.get("ZHENGJIANHAOMA").toString();
            String mmRenyuanId = mmRenyuan.get("RENYUANID")==null?"":mmRenyuan.get("RENYUANID").toString();

            Renyuan mmAddRenyuan = new Renyuan();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");

            String mmDeptid = mmRenyuan.get("DEPTID")==null?"":mmRenyuan.get("DEPTID").toString();
            String mmDeptname = mmRenyuan.get("DEPTNAME")==null?"":mmRenyuan.get("DEPTNAME").toString();
            String mmRenyuanleibie = mmRenyuan.get("RENYUANLEIBIE")==null?"":mmRenyuan.get("RENYUANLEIBIE").toString();
            String mmRenyuanleibie_tex = mmRenyuan.get("RENYUANLEIBIETEXT")==null?"":mmRenyuan.get("RENYUANLEIBIETEXT").toString();
            String mmTruename = mmRenyuan.get("TRUENAME")==null?"":mmRenyuan.get("TRUENAME").toString();
            String mmZhengjianleixing = mmRenyuan.get("ZHENGJIANLEIXING")==null?"":mmRenyuan.get("ZHENGJIANLEIXING").toString();
            String mmZhengjianleixing_tex = mmRenyuan.get("ZHENGJIANLEIXINGTEXT")==null?"":mmRenyuan.get("ZHENGJIANLEIXINGTEXT").toString();
            String mmBuzhibie = mmRenyuan.get("BUZHIBIE")==null?"":mmRenyuan.get("BUZHIBIE").toString();
            String mmJunxiandengji = mmRenyuan.get("JUNXIANDENGJI")==null?"":mmRenyuan.get("JUNXIANDENGJI").toString();
            String mmJunxiandengjitext = mmRenyuan.get("JUNXIANDENGJITEXT")==null?"":mmRenyuan.get("JUNXIANDENGJITEXT").toString();
            String mmJunxianleibie = mmRenyuan.get("JUNXIANLEIBIE")==null?"":mmRenyuan.get("JUNXIANLEIBIE").toString();
            String mmJunxianleibietext = mmRenyuan.get("JUNXIANLEIBIETEXT")==null?"":mmRenyuan.get("JUNXIANLEIBIETEXT").toString();
            String mmZhiwucengji = mmRenyuan.get("ZHIWUCENGJI")==null?"":mmRenyuan.get("ZHIWUCENGJI").toString();
            String mmZhiwucengjitext = mmRenyuan.get("ZHIWUCENGJITEXT")==null?"":mmRenyuan.get("ZHIWUCENGJITEXT").toString();
            String mmJXTIME = mmRenyuan.get("JXTIME")==null?"":mmRenyuan.get("JXTIME").toString();
            String mmZWTIME = mmRenyuan.get("ZWTIME")==null?"":mmRenyuan.get("ZWTIME").toString();
            String mmCSTIME = mmRenyuan.get("CSTIME")==null?"":mmRenyuan.get("CSTIME").toString();
            String mmJIGOUMINGCHENGMA = mmRenyuan.get("JIGOUMINGCHENGMA")==null?"":mmRenyuan.get("JIGOUMINGCHENGMA").toString();
            String mmSHIFOUJINGSHANG = mmRenyuan.get("SHIFOUJINGSHANG")==null?"":mmRenyuan.get("SHIFOUJINGSHANG").toString();
            String mmGuanliDeptid = mmDeptMap.get(mmJIGOUMINGCHENGMA)== null?"":mmDeptMap.get(mmJIGOUMINGCHENGMA);  // 通过机构名称码 查询管理端的单位id
            String mmORDERNUM = mmRenyuan.get("ORDERNUM")==null?"":mmRenyuan.get("ORDERNUM").toString();

            mmAddRenyuan.setTruename(MD5.convertMD5(mmTruename));
            mmAddRenyuan.setJigoumingchengma(mmJIGOUMINGCHENGMA);
            mmAddRenyuan.setRenyuanleibie(mmRenyuanleibie);
            mmAddRenyuan.setRenyuanleibietext(mmRenyuanleibie_tex);
            mmAddRenyuan.setRenyuanid(mmRenyuanId);
            mmAddRenyuan.setIsvalid(1);
            mmAddRenyuan.setDeptname(MD5.convertMD5(mmDeptname));
            mmAddRenyuan.setDeptid(mmDeptid);
            mmAddRenyuan.setZhengjianhaoma(MD5.convertMD5(mmZhengjainhaoma));
            mmAddRenyuan.setBuzhibie(MD5.convertMD5(mmBuzhibie));
            mmAddRenyuan.setChusheng(sdf.parse(mmCSTIME));
            mmAddRenyuan.setJunxiandengji(mmJunxiandengji);
            mmAddRenyuan.setJunxiandengjitext(MD5.convertMD5(mmJunxiandengjitext));
            mmAddRenyuan.setJunxianleibie(mmJunxianleibie);
            mmAddRenyuan.setJunxianleibietext(mmJunxianleibietext);
            mmAddRenyuan.setJunxianshijian(mmJXTIME==""?null:sdf.parse(mmJXTIME));
            mmAddRenyuan.setZhengjianleixing(mmZhengjianleixing);
            mmAddRenyuan.setZhengjianleixingtext(mmZhengjianleixing_tex);
            mmAddRenyuan.setZhiwushijian(sdf.parse(mmZWTIME));
            mmAddRenyuan.setZhiwucengji(mmZhiwucengji);
            mmAddRenyuan.setZhiwucengjitext(MD5.convertMD5(mmZhiwucengjitext));
            mmAddRenyuan.setShifoujingshang(Integer.parseInt(mmSHIFOUJINGSHANG));
            mmAddRenyuan.setJigoumingchengma(mmJIGOUMINGCHENGMA);
            mmAddRenyuan.setGuanlideptid(mmGuanliDeptid);
            mmAddRenyuan.setOrdernum(Integer.parseInt(mmORDERNUM));

            // 添加
            ddRenyuanMapper.insert(mmAddRenyuan);

        }// 结束人员的循环

        // 循环家属集合
        for(int c=0;c<JiashuList.size();c++){
            Map<String,Object> mmJiashu = JiashuList.get(c);

            // 创建家属
            Jiashu mmDangqianJiashu = new Jiashu();
            String mmJiashuId = mmJiashu.get("JIASHUID") == null? "" :mmJiashu.get("JIASHUID").toString(); // 获得家属id
            String mmGuanxi  = mmJiashu.get("GUANXI")== null? "" :mmJiashu.get("GUANXI").toString();
            String mmGuanxiText  = mmJiashu.get("GUANXITEXT")== null? "" :mmJiashu.get("GUANXITEXT").toString();
            String mmName  = mmJiashu.get("NAME")== null? "" :mmJiashu.get("NAME").toString();
            String mmShenfengzhenghao  = mmJiashu.get("SHENFENZHENGHAO")== null? "" :mmJiashu.get("SHENFENZHENGHAO").toString();
            String mmRenyuanId  = mmJiashu.get("RENYUANID")== null? "" :mmJiashu.get("RENYUANID").toString();

            mmDangqianJiashu.setGuanxi(mmGuanxi);
            mmDangqianJiashu.setGuanxitext(mmGuanxiText);
            mmDangqianJiashu.setIsvalid(1);
            mmDangqianJiashu.setJiashuid(mmJiashuId);
            mmDangqianJiashu.setName(mmName);
            mmDangqianJiashu.setRenyuanid(mmRenyuanId);
            mmDangqianJiashu.setShenfenzhenghao(mmShenfengzhenghao);

            // 添加家属
            ddJiashuMapper.insert(mmDangqianJiashu);

        }// 结束家属的循环

        //循环经商信息
        for(int d= 0;d<JingshangList.size();d++){
            Map<String,Object> mmJingshang = JingshangList.get(d);

            String mmJingshangId = mmJingshang.get("ID")==null?"":mmJingshang.get("ID").toString();
            String mmRenyuanId = mmJingshang.get("RENYUANID")==null?"":mmJingshang.get("RENYUANID").toString();
            String mmJingyingfanwei = mmJingshang.get("JINGYINGFANWEI")==null?"":mmJingshang.get("JINGYINGFANWEI").toString();
            String mmJingyingzhuangtai = mmJingshang.get("JINGYINGZHUANGTAI")==null?"":mmJingshang.get("JINGYINGZHUANGTAI").toString();
            String mmJingyingzhuangtaiText = mmJingshang.get("JINGYINGZHUANGTAITEXT")==null?"":mmJingshang.get("JINGYINGZHUANGTAITEXT").toString();
            String mmQianwujiaoyiduixiangname = mmJingshang.get("QIANWUJIAOYIDUIXIANGNAME")==null?"":mmJingshang.get("QIANWUJIAOYIDUIXIANGNAME").toString();
            String mmQianwushangpinhuofuwuname = mmJingshang.get("QIANWUSHANGPINHUOFUWUNAME")==null?"":mmJingshang.get("QIANWUSHANGPINHUOFUWUNAME").toString();
            String mmQiyename = mmJingshang.get("QIYENAME")==null?"":mmJingshang.get("QIYENAME").toString();
            String mmRenjiaochuzie = mmJingshang.get("RENJIAOCHUZIE")==null?"":mmJingshang.get("RENJIAOCHUZIE").toString();
            String mmShifouyouzhijieguanxi = mmJingshang.get("SHIFOUYOUZHIJIEGUANXI")==null?"":mmJingshang.get("SHIFOUYOUZHIJIEGUANXI").toString();
            String mmzhiwu = mmJingshang.get("ZHIWU")==null?"":mmJingshang.get("ZHIWU").toString();
            String mmZhiwuText = mmJingshang.get("ZHIWUTEXT")==null?"":mmJingshang.get("ZHIWUTEXT").toString();
            String mmLEIXING = mmJingshang.get("LEIXING")==null?"":mmJingshang.get("LEIXING").toString();
            String mmLEIXINGText = mmJingshang.get("LEIXINGTEXT")==null?"":mmJingshang.get("LEIXINGTEXT").toString();
            String mmDangqianJiashuId = mmJingshang.get("JIASHUID")==null?"":mmJingshang.get("JIASHUID").toString();
            String mmJinsanzhijieguanximingcheng = mmJingshang.get("JINSANZHIJIEGUANXIMINGCHENG") == null?"": mmJingshang.get("JINSANZHIJIEGUANXIMINGCHENG").toString();
            String mmShijunduimingcheng = mmJingshang.get("SHIJUNDUIMINGCHENG") == null?"": mmJingshang.get("SHIJUNDUIMINGCHENG").toString();
            String mmshehuixinyongdaima = mmJingshang.get("SHEHUIXINYONGDAIMA") == null?"": mmJingshang.get("SHEHUIXINYONGDAIMA").toString();

            // 添加经商情况
            JingshangQingkuang mmAddJingshangqingkuang = new JingshangQingkuang();

            mmAddJingshangqingkuang.setJiashuid(mmDangqianJiashuId);
            mmAddJingshangqingkuang.setId(mmJingshangId);
            mmAddJingshangqingkuang.setIsvalid(1);
            mmAddJingshangqingkuang.setJingyingfanwei(mmJingyingfanwei);
            mmAddJingshangqingkuang.setJingyingzhuangtai(mmJingyingzhuangtai);
            mmAddJingshangqingkuang.setQianwujiaoyiduixiangname(mmQianwujiaoyiduixiangname);
            mmAddJingshangqingkuang.setQianwushangpinhuofuwuname(mmQianwushangpinhuofuwuname);
            mmAddJingshangqingkuang.setQiyename(mmQiyename);
            mmAddJingshangqingkuang.setRenjiaochuzie(mmRenjiaochuzie);
            mmAddJingshangqingkuang.setRenyuanid(mmRenyuanId);
            mmAddJingshangqingkuang.setShifouyouzhijieguanxi(Integer.valueOf(mmShifouyouzhijieguanxi).intValue());
            mmAddJingshangqingkuang.setZhiwu(mmzhiwu);
            mmAddJingshangqingkuang.setLeixing(mmLEIXING);
            mmAddJingshangqingkuang.setLeixingtext(mmLEIXINGText);
            mmAddJingshangqingkuang.setJingyingzhuangtaitext(mmJingyingzhuangtaiText);
            mmAddJingshangqingkuang.setZhiwutext(mmZhiwuText);

            mmAddJingshangqingkuang.setJinsanzhijieguanximingcheng(mmJinsanzhijieguanximingcheng);
            mmAddJingshangqingkuang.setShijunduimingcheng(mmShijunduimingcheng);
            mmAddJingshangqingkuang.setShehuixinyongdaima(mmshehuixinyongdaima);


            // 执行添加方法
            ddJingshangMapper.insert(mmAddJingshangqingkuang);

        }// 结束经商循环


        // 添加操作纪录
        Caozuojilu mmCaozuojilu = new Caozuojilu();
        mmCaozuojilu.setDeptid(mmDaoruDeptId);
        mmCaozuojilu.setId(UUID.randomUUID().toString());
        mmCaozuojilu.setJiashunumber(AddJiashuNum);
        mmCaozuojilu.setJingshangnumber(AddJingshangNum);
        mmCaozuojilu.setLeixing("jingshang");
        mmCaozuojilu.setRenyuannumber(AddRenyuanNum);
        mmCaozuojilu.setUpdatetime(new Date());

        mmCaozuojiluService.add(mmCaozuojilu);

        Map<String,Object> mmAddNum = new HashMap<>();
        mmAddNum.put("renyuannum",AddRenyuanNum);
        mmAddNum.put("jiashunum",AddJiashuNum);
        mmAddNum.put("jingshangnum",AddJingshangNum);
        mmAddNum.put("shanchurenyuan",mmShanchuRenyuan);
        mmAddNum.put("shanchujiashu",mmShanchuJiashu);
        mmAddNum.put("shanchujingshang",mmShanchuJingshang);

        return JsonResult.getSuccessResult(mmAddNum);

    }


//    // 导入人员及家属经商情况
//    @Transactional
//    public JsonResult<?> DaoruJingshangQingkuang(String ppDeptId, String ppFileLujing) throws ParseException {
//
//        String userfilepath = USERFILEPATH;
//        String mmWenjian = ppFileLujing.split("userfiles")[1];
//        userfilepath=userfilepath+mmWenjian;
//
//        List<String> mmRenyuanidList = ddRenyuanMapper.selectRenyuanIdList(); // 获得人员集合
//        List<Dept> mmGuanliDeptList = ddDeptService.findAll();    // 获得管理员端的单位信息集合
//
//        // 将管理端单位id和机构名称码 对应存储
//        Map<String, String> mmDeptMap = new HashMap<>();
//        for(int a=0;a<mmGuanliDeptList.size();a++){
//            mmDeptMap.put(mmGuanliDeptList.get(a).getJigoumingchengma(),mmGuanliDeptList.get(a).getDeptid());
//        }
//
//
//        String Json = CreateJSON.readJsonFile(userfilepath);
//        JSONObject mmObjectJson = JSONObject.parseObject(Json);
//        Map<String, Object> mmDaoruMap =  (Map<String, Object>)mmObjectJson;
//
//        int AddRenyuanNum = 0;
//        int AddJiashuNum = 0;
//        int AddJingshangNum = 0;
//
//        // 判断是否为当前单位
//        String mmDaoruDeptId = mmDaoruMap.get("DEPTID")== null ?"":mmDaoruMap.get("DEPTID").toString();
//
//        // 获得单位List 将这些单位的干部 家属 经商信息删除。
//        List<Map<String,Object>> mmDeptList = mmDaoruMap.get("DEPTLIST")==null? null:(List<Map<String,Object>>) mmDaoruMap.get("DEPTLIST");
//        for(int b = 0;b < mmDeptList.size();b++) {
//            String mmDeptId = mmDeptList.get(b).get("DEPTID") == null ? "" : mmDeptList.get(b).get("DEPTID").toString();
//            // 将该单位的经商数据删除。
//            List<String> mmRenyuanIdList = ddRenyuanMapper.selectRenyuanIdByDeptId(mmDeptId);
//            for (int a = 0; a < mmRenyuanIdList.size(); a++) {
//                //循环删除该单位的所有数据
//                deleteAllRenyuanByRenyuanId(mmRenyuanIdList.get(a));
//            }
//        }
//
//        // 获得人员List
//        List<Map<String,Object>> JingshangRenyuanList = mmDaoruMap.get("RENYUANLIST")==null? null:(List<Map<String,Object>>) mmDaoruMap.get("RENYUANLIST");
//        AddRenyuanNum = JingshangRenyuanList.size();
//        // 循环人员集合
//        for(int i=0;i<JingshangRenyuanList.size();i++){
//            Map<String,Object> mmRenyuan = JingshangRenyuanList.get(i);
//            // 获得当前人员id 及证件号码
//            String mmZhengjainhaoma = mmRenyuan.get("ZHENGJIANHAOMA")==null?"":mmRenyuan.get("ZHENGJIANHAOMA").toString();
//            String mmRenyuanId = mmRenyuan.get("RENYUANID")==null?"":mmRenyuan.get("RENYUANID").toString();
//
//            // 根据人员id判断该人员是否存在 存在则删除他的所有信息 导入最新的信息
//            if(mmRenyuanidList.contains(mmRenyuanId)){
//                // 删除 人员 家属 经商情况
//                deleteAllRenyuanByRenyuanId(mmRenyuanId);
//            }
//
//            Renyuan mmAddRenyuan = new Renyuan();
//            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
//
//            String mmDeptid = mmRenyuan.get("DEPTID")==null?"":mmRenyuan.get("DEPTID").toString();
//            String mmDeptname = mmRenyuan.get("DEPTNAME")==null?"":mmRenyuan.get("DEPTNAME").toString();
//            String mmRenyuanleibie = mmRenyuan.get("RENYUANLEIBIE")==null?"":mmRenyuan.get("RENYUANLEIBIE").toString();
//            String mmRenyuanleibie_tex = mmRenyuan.get("RENYUANLEIBIETEXT")==null?"":mmRenyuan.get("RENYUANLEIBIETEXT").toString();
//            String mmTruename = mmRenyuan.get("TRUENAME")==null?"":mmRenyuan.get("TRUENAME").toString();
//            String mmZhengjianleixing = mmRenyuan.get("ZHENGJIANLEIXING")==null?"":mmRenyuan.get("ZHENGJIANLEIXING").toString();
//            String mmZhengjianleixing_tex = mmRenyuan.get("ZHENGJIANLEIXINGTEXT")==null?"":mmRenyuan.get("ZHENGJIANLEIXINGTEXT").toString();
//            String mmBuzhibie = mmRenyuan.get("BUZHIBIE")==null?"":mmRenyuan.get("BUZHIBIE").toString();
//            String mmJunxiandengji = mmRenyuan.get("JUNXIANDENGJI")==null?"":mmRenyuan.get("JUNXIANDENGJI").toString();
//            String mmJunxiandengjitext = mmRenyuan.get("JUNXIANDENGJITEXT")==null?"":mmRenyuan.get("JUNXIANDENGJITEXT").toString();
//            String mmJunxianleibie = mmRenyuan.get("JUNXIANLEIBIE")==null?"":mmRenyuan.get("JUNXIANLEIBIE").toString();
//            String mmJunxianleibietext = mmRenyuan.get("JUNXIANLEIBIETEXT")==null?"":mmRenyuan.get("JUNXIANLEIBIETEXT").toString();
//            String mmZhiwucengji = mmRenyuan.get("ZHIWUCENGJI")==null?"":mmRenyuan.get("ZHIWUCENGJI").toString();
//            String mmZhiwucengjitext = mmRenyuan.get("ZHIWUCENGJITEXT")==null?"":mmRenyuan.get("ZHIWUCENGJITEXT").toString();
//            String mmJXTIME = mmRenyuan.get("JXTIME")==null?"":mmRenyuan.get("JXTIME").toString();
//            String mmZWTIME = mmRenyuan.get("ZWTIME")==null?"":mmRenyuan.get("ZWTIME").toString();
//            String mmCSTIME = mmRenyuan.get("CSTIME")==null?"":mmRenyuan.get("CSTIME").toString();
//            String mmJIGOUMINGCHENGMA = mmRenyuan.get("JIGOUMINGCHENGMA")==null?"":mmRenyuan.get("JIGOUMINGCHENGMA").toString();
//            String mmSHIFOUJINGSHANG = mmRenyuan.get("SHIFOUJINGSHANG")==null?"":mmRenyuan.get("SHIFOUJINGSHANG").toString();
//            String mmGuanliDeptid = mmDeptMap.get(mmJIGOUMINGCHENGMA)== null?"":mmDeptMap.get(mmJIGOUMINGCHENGMA);  // 通过机构名称码 查询管理端的单位id
//
//            mmAddRenyuan.setTruename(MD5.convertMD5(mmTruename));
//            mmAddRenyuan.setJigoumingchengma(mmJIGOUMINGCHENGMA);
//            mmAddRenyuan.setRenyuanleibie(mmRenyuanleibie);
//            mmAddRenyuan.setRenyuanleibietext(mmRenyuanleibie_tex);
//            mmAddRenyuan.setRenyuanid(mmRenyuanId);
//            mmAddRenyuan.setIsvalid(1);
//            mmAddRenyuan.setDeptname(MD5.convertMD5(mmDeptname));
//            mmAddRenyuan.setDeptid(mmDeptid);
//            mmAddRenyuan.setZhengjianhaoma(MD5.convertMD5(mmZhengjainhaoma));
//            mmAddRenyuan.setBuzhibie(MD5.convertMD5(mmBuzhibie));
//            mmAddRenyuan.setChusheng(sdf.parse(mmCSTIME));
//            mmAddRenyuan.setJunxiandengji(mmJunxiandengji);
//            mmAddRenyuan.setJunxiandengjitext(MD5.convertMD5(mmJunxiandengjitext));
//            mmAddRenyuan.setJunxianleibie(mmJunxianleibie);
//            mmAddRenyuan.setJunxianleibietext(mmJunxianleibietext);
//            mmAddRenyuan.setJunxianshijian(mmJXTIME==""?null:sdf.parse(mmJXTIME));
//            mmAddRenyuan.setZhengjianleixing(mmZhengjianleixing);
//            mmAddRenyuan.setZhengjianleixingtext(mmZhengjianleixing_tex);
//            mmAddRenyuan.setZhiwushijian(sdf.parse(mmZWTIME));
//            mmAddRenyuan.setZhiwucengji(mmZhiwucengji);
//            mmAddRenyuan.setZhiwucengjitext(MD5.convertMD5(mmZhiwucengjitext));
//            mmAddRenyuan.setShifoujingshang(Integer.parseInt(mmSHIFOUJINGSHANG));
//            mmAddRenyuan.setGuanlideptid(mmGuanliDeptid);
//
//            // 添加
//            ddRenyuanMapper.insert(mmAddRenyuan);
//
//            // 获得家属集合 ，如不为空 则添加家属
//            List<Map<String,Object>> mmSuoshuJiashu = mmRenyuan.get("JIASHULIST")==null? null:(List<Map<String,Object>>) mmRenyuan.get("JIASHULIST");
//            AddJiashuNum = AddJiashuNum + mmSuoshuJiashu.size();
//            if(mmSuoshuJiashu!=null){
//                // 循环家属
//                for(int z=0;z<mmSuoshuJiashu.size();z++){
//
//                    Map<String,Object> mmDangqianjiashu = mmSuoshuJiashu.get(z);
//                    String mmJiashuId = mmDangqianjiashu.get("JIASHUID") == null? "" :mmDangqianjiashu.get("JIASHUID").toString(); // 获得家属id
//                    // 如不存在该主键就添加家属信息
//
//                    Jiashu mmDangqianJiashu = new Jiashu();
//                    String mmGuanxi  = mmDangqianjiashu.get("GUANXI")== null? "" :mmDangqianjiashu.get("GUANXI").toString();
//                    String mmGuanxiText  = mmDangqianjiashu.get("GUANXITEXT")== null? "" :mmDangqianjiashu.get("GUANXITEXT").toString();
//                    String mmName  = mmDangqianjiashu.get("NAME")== null? "" :mmDangqianjiashu.get("NAME").toString();
//                    String mmShenfengzhenghao  = mmDangqianjiashu.get("SHENFENZHENGHAO")== null? "" :mmDangqianjiashu.get("SHENFENZHENGHAO").toString();
//
//                    mmDangqianJiashu.setGuanxi(mmGuanxi);
//                    mmDangqianJiashu.setGuanxitext(mmGuanxiText);
//                    mmDangqianJiashu.setIsvalid(1);
//                    mmDangqianJiashu.setJiashuid(mmJiashuId);
//                    mmDangqianJiashu.setName(mmName);
//                    mmDangqianJiashu.setRenyuanid(mmRenyuanId);
//                    mmDangqianJiashu.setShenfenzhenghao(mmShenfengzhenghao);
//
//                    // 添加家属
//                    ddJiashuMapper.insert(mmDangqianJiashu);
//
//                    // 查询当前家属的经商信息
//                    List<Map<String,Object>> mmSuoshuJingshang = mmDangqianjiashu.get("JINGSHANGLIST")==null? null:(List<Map<String,Object>>) mmDangqianjiashu.get("JINGSHANGLIST");
//
//                    if(mmSuoshuJingshang!=null){
//                        AddJingshangNum = AddJingshangNum + mmSuoshuJingshang.size();
//                        for(int x=0;x<mmSuoshuJingshang.size();x++){
//
//                            Map<String,Object> mmJingshangqingkuang = mmSuoshuJingshang.get(x);
//
//                            String mmJingshangId = mmJingshangqingkuang.get("ID")==null?"":mmJingshangqingkuang.get("ID").toString();
//                            String mmJingyingfanwei = mmJingshangqingkuang.get("JINGYINGFANWEI")==null?"":mmJingshangqingkuang.get("JINGYINGFANWEI").toString();
//                            String mmJingyingzhuangtai = mmJingshangqingkuang.get("JINGYINGZHUANGTAI")==null?"":mmJingshangqingkuang.get("JINGYINGZHUANGTAI").toString();
//                            String mmJingyingzhuangtaiText = mmJingshangqingkuang.get("JINGYINGZHUANGTAITEXT")==null?"":mmJingshangqingkuang.get("JINGYINGZHUANGTAITEXT").toString();
//                            String mmQianwujiaoyiduixiangname = mmJingshangqingkuang.get("QIANWUJIAOYIDUIXIANGNAME")==null?"":mmJingshangqingkuang.get("QIANWUJIAOYIDUIXIANGNAME").toString();
//                            String mmQianwushangpihuofuwunname = mmJingshangqingkuang.get("QIANWUSHANGPINHUOFUWUNAME")==null?"":mmJingshangqingkuang.get("QIANWUSHANGPINHUOFUWUNAME").toString();
//                            String mmQiyename = mmJingshangqingkuang.get("QIYENAME")==null?"":mmJingshangqingkuang.get("QIYENAME").toString();
//                            String mmRenjiaochuzie = mmJingshangqingkuang.get("RENJIAOCHUZIE")==null?"":mmJingshangqingkuang.get("RENJIAOCHUZIE").toString();
//                            String mmShifouyouzhijieguanxi = mmJingshangqingkuang.get("SHIFOUYOUZHIJIEGUANXI")==null?"":mmJingshangqingkuang.get("SHIFOUYOUZHIJIEGUANXI").toString();
//                            String mmzhiwu = mmJingshangqingkuang.get("ZHIWU")==null?"":mmJingshangqingkuang.get("ZHIWU").toString();
//                            String mmZhiwuText = mmJingshangqingkuang.get("ZHIWUTEXT")==null?"":mmJingshangqingkuang.get("ZHIWUTEXT").toString();
//                            String mmLEIXING = mmJingshangqingkuang.get("LEIXING")==null?"":mmJingshangqingkuang.get("LEIXING").toString();
//                            String mmLEIXINGText = mmJingshangqingkuang.get("LEIXINGTEXT")==null?"":mmJingshangqingkuang.get("LEIXINGTEXT").toString();
//                            String mmDangqianJiashuId = mmJingshangqingkuang.get("JIASHUID")==null?"":mmJingshangqingkuang.get("JIASHUID").toString();
//                            String mmJinsanzhijieguanximingcheng = mmJingshangqingkuang.get("JINSANZHIJIEGUANXIMINGCHENG") == null?"": mmJingshangqingkuang.get("JINSANZHIJIEGUANXIMINGCHENG").toString();
//                            String mmShijunduimingcheng = mmJingshangqingkuang.get("SHIJUNDUIMINGCHENG") == null?"": mmJingshangqingkuang.get("SHIJUNDUIMINGCHENG").toString();
//                            String mmShehuixinyongdaima = mmJingshangqingkuang.get("SHEHUIXINYONGDAIMA") == null?"": mmJingshangqingkuang.get("SHEHUIXINYONGDAIMA").toString();
//
//                            // 添加经商情况
//                            JingshangQingkuang mmAddJingshangqingkuang = new JingshangQingkuang();
//
//                            mmAddJingshangqingkuang.setJiashuid(mmDangqianJiashuId);
//                            mmAddJingshangqingkuang.setId(mmJingshangId);
//                            mmAddJingshangqingkuang.setIsvalid(1);
//                            mmAddJingshangqingkuang.setJingyingfanwei(mmJingyingfanwei);
//                            mmAddJingshangqingkuang.setJingyingzhuangtai(mmJingyingzhuangtai);
//                            mmAddJingshangqingkuang.setQianwujiaoyiduixiangname(mmQianwujiaoyiduixiangname);
//                            mmAddJingshangqingkuang.setQianwushangpinhuofuwuname(mmQianwushangpihuofuwunname);
//                            mmAddJingshangqingkuang.setQiyename(mmQiyename);
//                            mmAddJingshangqingkuang.setRenjiaochuzie(mmRenjiaochuzie);
//                            mmAddJingshangqingkuang.setRenyuanid(mmRenyuanId);
//                            mmAddJingshangqingkuang.setShifouyouzhijieguanxi(Integer.valueOf(mmShifouyouzhijieguanxi).intValue());
//                            mmAddJingshangqingkuang.setZhiwu(mmzhiwu);
//                            mmAddJingshangqingkuang.setLeixing(mmLEIXING);
//                            mmAddJingshangqingkuang.setLeixingtext(mmLEIXINGText);
//                            mmAddJingshangqingkuang.setJingyingzhuangtaitext(mmJingyingzhuangtaiText);
//                            mmAddJingshangqingkuang.setZhiwutext(mmZhiwuText);
//
//                            mmAddJingshangqingkuang.setJinsanzhijieguanximingcheng(mmJinsanzhijieguanximingcheng);
//                            mmAddJingshangqingkuang.setShijunduimingcheng(mmShijunduimingcheng);
//                            mmAddJingshangqingkuang.setShehuixinyongdaima(mmShehuixinyongdaima);
//
//
//                            // 执行添加方法
//                            ddJingshangMapper.insert(mmAddJingshangqingkuang);
//
//                        }// 结束家属经商情况集合循环
//                    }
//
//                }// 结束人员家属集合的循环
//            }
//
//
//        }// 结束人员的循环
//        // 添加操作纪录
//        Caozuojilu mmCaozuojilu = new Caozuojilu();
//        mmCaozuojilu.setDeptid(mmDaoruDeptId);
//        mmCaozuojilu.setId(UUID.randomUUID().toString());
//        mmCaozuojilu.setJiashunumber(AddJiashuNum);
//        mmCaozuojilu.setJingshangnumber(AddJingshangNum);
//        mmCaozuojilu.setLeixing("jingshang");
//        mmCaozuojilu.setRenyuannumber(AddRenyuanNum);
//        mmCaozuojilu.setUpdatetime(new Date());
//
//        mmCaozuojiluService.add(mmCaozuojilu);
//
//        Map<String,Object> mmAddNum = new HashMap<>();
//        mmAddNum.put("renyuannum",AddRenyuanNum);
//        mmAddNum.put("jiashunum",AddJiashuNum);
//        mmAddNum.put("jingshangnum",AddJingshangNum);
//
//        return JsonResult.getSuccessResult(mmAddNum);
//
//    }
//

    // 导入甄别情况
    @Transactional
    public JsonResult<?> DaoruZhenbieQingkuang(String ppDeptId, String ppFileLujing) throws ParseException {
        String userfilepath = USERFILEPATH;
        String mmWenjian = ppFileLujing.split("userfiles")[1];

        userfilepath=userfilepath+mmWenjian;

        // 查询甄别id集合
        List<String> mmZhenbieidList = ddZhenbieService.selectZhenbieIdList();

        String Json = CreateJSON.readJsonFile(userfilepath);
        JSONObject mmObjectJson = JSONObject.parseObject(Json);
        Map<String, Object> mmDaoruMap =  (Map<String, Object>)mmObjectJson;

        // 获得甄别List
        List<Map<String,Object>> ZhenbieList = mmDaoruMap.get("ZHENBIELIST")==null? null:(List<Map<String,Object>>) mmDaoruMap.get("ZHENBIELIST");
        int AddZhenbieNum = ZhenbieList.size(); // 本次操作添加的甄别数据的数量
        // 循环集合
        for(int i=0;i<ZhenbieList.size();i++){
            Map<String,Object> mmZhenbie = ZhenbieList.get(i);

            // 获得甄别id
            String mmZhenbieId = mmZhenbie.get("ID")==null?"":mmZhenbie.get("ID").toString();

            // 根据id判断该甄别数据是否存在 存在则删除
            if(mmZhenbieidList.contains(mmZhenbieId)){
                // 删除甄别情况
                ddZhenbieService.delete(mmZhenbieId);
            }

            ZhenbieQingkuang mmAddZhenbie = new ZhenbieQingkuang();

            String mmId = mmZhenbie.get("ID")==null?"":mmZhenbie.get("ID").toString();
            String mmBEIZHU = mmZhenbie.get("BEIZHU")==null?"":mmZhenbie.get("BEIZHU").toString();
            String mmBENRENTUICHU = mmZhenbie.get("BENRENTUICHU")==null?"":mmZhenbie.get("BENRENTUICHU").toString();
            String mmBUGUIFANYUANYIN = mmZhenbie.get("BUGUIFANYUANYIN")==null?"":mmZhenbie.get("BUGUIFANYUANYIN").toString();
            String mmDENGJIZHUANGTAI = mmZhenbie.get("DENGJIZHUANGTAI")==null?"":mmZhenbie.get("DENGJIZHUANGTAI").toString();
            String mmJIASHUID = mmZhenbie.get("JIASHUID")==null?"":mmZhenbie.get("JIASHUID").toString();
            String mmJINGSHANGID = mmZhenbie.get("JINGSHANGID")==null?"":mmZhenbie.get("JINGSHANGID").toString();
            String mmJINGSHANGJUTIXINGTAI = mmZhenbie.get("JINGSHANGJUTIXINGTAI")==null?"":mmZhenbie.get("JINGSHANGJUTIXINGTAI").toString();
            String mmJINGYINGFANWEI = mmZhenbie.get("JINGYINGFANWEI")==null?"":mmZhenbie.get("JINGYINGFANWEI").toString();
            String mmJINGYINGZHUANGTAI = mmZhenbie.get("JINGYINGZHUANGTAI")==null?"":mmZhenbie.get("JINGYINGZHUANGTAI").toString();
            String mmJINGYINGZHUANGTAITEXT = mmZhenbie.get("JINGYINGZHUANGTAITEXT")==null?"":mmZhenbie.get("JINGYINGZHUANGTAITEXT").toString();
            String mmJINSANZHIJIEGUANXIMINGCHENG = mmZhenbie.get("JINSANZHIJIEGUANXIMINGCHENG")==null?"":mmZhenbie.get("JINSANZHIJIEGUANXIMINGCHENG").toString();
            String mmLEIXING = mmZhenbie.get("LEIXING")==null?"":mmZhenbie.get("LEIXING").toString();
            String mmLEIXINGTEXT = mmZhenbie.get("LEIXINGTEXT")==null?"":mmZhenbie.get("LEIXINGTEXT").toString();
            String mmQIANWUJIAOYIDUIXIANGNAME = mmZhenbie.get("QIANWUJIAOYIDUIXIANGNAME")==null?"":mmZhenbie.get("QIANWUJIAOYIDUIXIANGNAME").toString();
            String mmQIANWUSHANGPINHUOFUWUNAME = mmZhenbie.get("QIANWUSHANGPINHUOFUWUNAME")==null?"":mmZhenbie.get("QIANWUSHANGPINHUOFUWUNAME").toString();
            String mmQIYENAME = mmZhenbie.get("QIYENAME")==null?"":mmZhenbie.get("QIYENAME").toString();
            String mmQIYESUOZAIDI = mmZhenbie.get("QIYESUOZAIDI")==null?"":mmZhenbie.get("QIYESUOZAIDI").toString();
            String mmRENJIAOCHUZIE = mmZhenbie.get("RENJIAOCHUZIE")==null?"":mmZhenbie.get("RENJIAOCHUZIE").toString();
            String mmRENYUANID = mmZhenbie.get("RENYUANID")==null?"":mmZhenbie.get("RENYUANID").toString();
            String mmSHEHUIXINYONGDAIMA = mmZhenbie.get("SHEHUIXINYONGDAIMA")==null?"":mmZhenbie.get("SHEHUIXINYONGDAIMA").toString();
            String mmSHIFOUGUIFAN = mmZhenbie.get("SHIFOUGUIFAN")==null?"":mmZhenbie.get("SHIFOUGUIFAN").toString();
            String mmSHIFOUJINGSHANG = mmZhenbie.get("SHIFOUJINGSHANG")==null?"":mmZhenbie.get("SHIFOUJINGSHANG").toString();
            String mmSHIFOUYOUZHIJIEGUANXI = mmZhenbie.get("SHIFOUYOUZHIJIEGUANXI")==null?"":mmZhenbie.get("SHIFOUYOUZHIJIEGUANXI").toString();
            String mmSHIJUNDUIMINGCHENG = mmZhenbie.get("SHIJUNDUIMINGCHENG")==null?"":mmZhenbie.get("SHIJUNDUIMINGCHENG").toString();
            String mmTUICHUJINGSHANG = mmZhenbie.get("TUICHUJINGSHANG")==null?"":mmZhenbie.get("TUICHUJINGSHANG").toString();
            String mmTUICHUQINGKUANG = mmZhenbie.get("TUICHUQINGKUANG")==null?"":mmZhenbie.get("TUICHUQINGKUANG").toString();
            String mmZHIWU = mmZhenbie.get("ZHIWU")==null?"":mmZhenbie.get("ZHIWU").toString();
            String mmZHIWUTEXT = mmZhenbie.get("ZHIWUTEXT")==null?"":mmZhenbie.get("ZHIWUTEXT").toString();
            String mmZHUCEZIBEN = mmZhenbie.get("ZHUCEZIBEN")==null?"":mmZhenbie.get("ZHUCEZIBEN").toString();


            mmAddZhenbie.setId(mmId);
            mmAddZhenbie.setBeizhu(mmBEIZHU);
            mmAddZhenbie.setBenrentuichu(mmBENRENTUICHU);
            mmAddZhenbie.setBuguifanyuanyin(mmBUGUIFANYUANYIN);
            mmAddZhenbie.setDengjizhuangtai(mmDENGJIZHUANGTAI);
            mmAddZhenbie.setIsvalid(1);
            mmAddZhenbie.setJiashuid(mmJIASHUID);
            mmAddZhenbie.setJingshangid(mmJINGSHANGID);
            mmAddZhenbie.setJingshangjutixingtai(mmJINGSHANGJUTIXINGTAI);
            mmAddZhenbie.setJingyingfanwei(mmJINGYINGFANWEI);
            mmAddZhenbie.setJingyingzhuangtai(mmJINGYINGZHUANGTAI);
            mmAddZhenbie.setJingyingzhuangtaitext(mmJINGYINGZHUANGTAITEXT);
            mmAddZhenbie.setJinsanzhijieguanximingcheng(mmJINSANZHIJIEGUANXIMINGCHENG);
            mmAddZhenbie.setLeixing(mmLEIXING);
            mmAddZhenbie.setLeixingtext(mmLEIXINGTEXT);
            mmAddZhenbie.setQianwujiaoyiduixiangname(mmQIANWUJIAOYIDUIXIANGNAME);
            mmAddZhenbie.setQianwushangpinhuofuwuname(mmQIANWUSHANGPINHUOFUWUNAME);
            mmAddZhenbie.setQiyename(mmQIYENAME);
            mmAddZhenbie.setQiyesuozaidi(mmQIYESUOZAIDI);
            mmAddZhenbie.setRenjiaochuzie(mmRENJIAOCHUZIE);
            mmAddZhenbie.setRenyuanid(mmRENYUANID);
            mmAddZhenbie.setShehuixinyongdaima(mmSHEHUIXINYONGDAIMA);
            if(!mmSHIFOUGUIFAN.equals("")){
                mmAddZhenbie.setShifouguifan(mmSHIFOUGUIFAN);
            }
            if(!mmSHIFOUJINGSHANG.equals("")){
                mmAddZhenbie.setShifoujingshang(mmSHIFOUJINGSHANG);
            }
            if(!mmSHIFOUYOUZHIJIEGUANXI.equals("")){
                mmAddZhenbie.setShifouyouzhijieguanxi(Integer.valueOf(mmSHIFOUYOUZHIJIEGUANXI));
            }
            if(!mmTUICHUQINGKUANG.equals("")){
                mmAddZhenbie.setTuichuqingkuang(Integer.valueOf(mmTUICHUQINGKUANG));
            }



            mmAddZhenbie.setShijunduimingcheng(mmSHIJUNDUIMINGCHENG);
            mmAddZhenbie.setTuichujingshang(mmTUICHUJINGSHANG);
            mmAddZhenbie.setUpdatetime(new Date());
            mmAddZhenbie.setZhiwu(mmZHIWU);
            mmAddZhenbie.setZhiwutext(mmZHIWUTEXT);
            mmAddZhenbie.setZhuceziben(mmZHUCEZIBEN);



            // 添加
            ddZhenbieService.add(mmAddZhenbie);

        }// 结束循环
        // 添加操作纪录
        Caozuojilu mmCaozuojilu = new Caozuojilu();
        mmCaozuojilu.setDeptid(ppDeptId);
        mmCaozuojilu.setId(UUID.randomUUID().toString());

        mmCaozuojilu.setLeixing("zhenbie");
        mmCaozuojilu.setChahenumber(AddZhenbieNum);
        mmCaozuojilu.setUpdatetime(new Date());

        mmCaozuojiluService.add(mmCaozuojilu);

        Map<String,Object> mmAddNum = new HashMap<>();

        mmAddNum.put("zhenbienum",AddZhenbieNum);

        return JsonResult.getSuccessResult(mmAddNum);

    }

    // 导入规范情况
    @Transactional
    public JsonResult<?> DaoruGuifanQingkuang(String ppDeptId, String ppFileLujing) throws ParseException {
        String userfilepath = USERFILEPATH;
        String mmWenjian = ppFileLujing.split("userfiles")[1];

        userfilepath=userfilepath+mmWenjian;

        // 查询规范id集合
        List<String> mmGuifanidList = ddGuifanMapper.findGuifanIdList();

        String Json = CreateJSON.readJsonFile(userfilepath);
        JSONObject mmObjectJson = JSONObject.parseObject(Json);
        Map<String, Object> mmDaoruMap =  (Map<String, Object>)mmObjectJson;

        // 获得规范List
        List<Map<String,Object>> GuifanList = mmDaoruMap.get("GUIFANLIST")==null? null:(List<Map<String,Object>>) mmDaoruMap.get("GUIFANLIST");
        int AddGuifanNum = GuifanList.size(); // 本次操作添加的规范数据的数量
        // 循环集合
        for(int i=0;i<GuifanList.size();i++){
            Map<String,Object> mmGuifanOne = GuifanList.get(i);

            // 获得规范id
            String mmGuifanId = mmGuifanOne.get("ID")==null?"":mmGuifanOne.get("ID").toString();

            // 根据id判断该规范数据是否存在 存在则删除
            if(mmGuifanidList.contains(mmGuifanId)){
                // 删除规范情况
                deleteGuifanAndFujianByGuifanId(mmGuifanId);
            }

            GuifanluoshiQingkuang mmAddGuifan = new GuifanluoshiQingkuang();

           // String mmId = mmGuifanOne.get("ID")==null?"":mmGuifanOne.get("ID").toString();
            String mmBEIZHU = mmGuifanOne.get("BEIZHU")==null?"":mmGuifanOne.get("BEIZHU").toString();
            String mmCHAHEID = mmGuifanOne.get("CHAHEID")==null?"":mmGuifanOne.get("CHAHEID").toString();
            String mmGUIFANLUOSHIZHUANGTAI = mmGuifanOne.get("GUIFANLUOSHIZHUANGTAI")==null?"":mmGuifanOne.get("GUIFANLUOSHIZHUANGTAI").toString();
            String mmJIASHUID = mmGuifanOne.get("JIASHUID")==null?"":mmGuifanOne.get("JIASHUID").toString();
            String mmJINGSHANGID = mmGuifanOne.get("JINGSHANGID")==null?"":mmGuifanOne.get("JINGSHANGID").toString();
            String mmQIYELEIXINGID = mmGuifanOne.get("QIYELEIXINGID")==null?"":mmGuifanOne.get("QIYELEIXINGID").toString();
            String mmRENYUANID = mmGuifanOne.get("RENYUANID")==null?"":mmGuifanOne.get("RENYUANID").toString();
            String mmTUICHUFANGSHIID = mmGuifanOne.get("TUICHUFANGSHIID")==null?"":mmGuifanOne.get("TUICHUFANGSHIID").toString();
            String mmTUICHULEIXING = mmGuifanOne.get("TUICHULEIXING")==null?"":mmGuifanOne.get("TUICHULEIXING").toString();
            String mmZHENBIEID = mmGuifanOne.get("ZHENBIEID")==null?"":mmGuifanOne.get("ZHENBIEID").toString();

            mmAddGuifan.setBeizhu(mmBEIZHU);
            mmAddGuifan.setChaheid(mmCHAHEID);
            mmAddGuifan.setGuifanluoshizhuangtai(mmGUIFANLUOSHIZHUANGTAI);
            mmAddGuifan.setId(mmGuifanId);
            mmAddGuifan.setIsvalid(1);
            mmAddGuifan.setJiashuid(mmJIASHUID);
            mmAddGuifan.setJingshangid(mmJINGSHANGID);
            mmAddGuifan.setQiyeleixingid(mmQIYELEIXINGID);
            mmAddGuifan.setRenyuanid(mmRENYUANID);
            mmAddGuifan.setTuichufangshiid(mmTUICHUFANGSHIID);

            if(!mmTUICHULEIXING.equals("")){
                mmAddGuifan.setTuichuleixing(Integer.valueOf(mmTUICHULEIXING));
            }
            mmAddGuifan.setUpdatetime(new Date());
            mmAddGuifan.setZhenbieid(mmZHENBIEID);
            // 添加规范数据
            ddGuifanMapper.insert(mmAddGuifan);

            // 查询当前家属的经商信息
            List<Map<String,Object>> mmSuoshuFujianList = mmGuifanOne.get("FUJIANLIST")==null? null:(List<Map<String,Object>>) mmGuifanOne.get("FUJIANLIST");

            if(mmSuoshuFujianList!=null){

                for(int x=0;x<mmSuoshuFujianList.size();x++){

                    Map<String, Object> mmFujianOne = mmSuoshuFujianList.get(x);
                    String mmDISPLAYTEXT = mmFujianOne.get("DISPLAYTEXT")==null?"":mmFujianOne.get("DISPLAYTEXT").toString();
                    String mmGUIFANLUOSHIID = mmFujianOne.get("GUIFANLUOSHIID")==null?"":mmFujianOne.get("GUIFANLUOSHIID").toString();
                    String mmID = mmFujianOne.get("ID")==null?"":mmFujianOne.get("ID").toString();
                    String mmNEWFILENAME = mmFujianOne.get("NEWFILENAME")==null?"":mmFujianOne.get("NEWFILENAME").toString();
                    String mmZHENGMINGCAILIAOID = mmFujianOne.get("ZHENGMINGCAILIAOID")==null?"":mmFujianOne.get("ZHENGMINGCAILIAOID").toString();

                    Fujian mmFujian = new Fujian();
                    mmFujian.setDisplaytext(mmDISPLAYTEXT);
                    mmFujian.setGuifanluoshiid(mmGUIFANLUOSHIID);

                    mmFujian.setId(mmID);
                    mmFujian.setIsvalid(1);
                    mmFujian.setNewfilename(mmNEWFILENAME);
                    mmFujian.setUploaddatetime(new Date());
                    mmFujian.setZhengmingcailiaoid(mmZHENGMINGCAILIAOID);
                    ddFujianService.add(mmFujian);
                }
            }


        }// 结束循环
        // 添加操作纪录
        Caozuojilu mmCaozuojilu = new Caozuojilu();
        mmCaozuojilu.setDeptid(ppDeptId);
        mmCaozuojilu.setId(UUID.randomUUID().toString());

        mmCaozuojilu.setLeixing("guifan");
        mmCaozuojilu.setChahenumber(AddGuifanNum);
        mmCaozuojilu.setUpdatetime(new Date());

        mmCaozuojiluService.add(mmCaozuojilu);

        Map<String,Object> mmAddNum = new HashMap<>();

        mmAddNum.put("guifannum",AddGuifanNum);

        return JsonResult.getSuccessResult(mmAddNum);

    }




    @Transactional
    public Map<String,Object> deleteAllRenyuanByRenyuanId(String ppRenyuanId) {
        Map<String,Object> ppMap = new HashMap<>();
        int deleteJingshang = ddJingshangqingkuangService.DeleteByRenyuanId(ppRenyuanId);
        if (deleteJingshang<0) {
            throw new RuntimeException("删除家属经商情况失败");
        }

        int deleteJiashu = ddJiashuService.deleteByRenyuanId(ppRenyuanId);
        if (deleteJiashu <0) {
            throw new RuntimeException("删除家属失败");
        }

        int deleteRenyuan = ddRenyuanMapper.deleteByPrimaryKey(ppRenyuanId);
        if (deleteRenyuan<0) {
            throw new RuntimeException("删除人员失败");
        }

        ppMap.put("deleteJingshang",deleteJingshang);
        ppMap.put("deleteJiashu",deleteJiashu);
        ppMap.put("deleteRenyuan",deleteRenyuan);

        return ppMap;
    }

    @Transactional
    public boolean deleteGuifanAndFujianByGuifanId(String ppGuifanId) {

        int deleteGuifan = ddGuifanMapper.deleteByPrimaryKey(ppGuifanId);

        if (deleteGuifan<0) {
            throw new RuntimeException("删除规范情况失败");
        }
        int deleteFujian = ddFujianService.deleteByGuifanId(ppGuifanId);

        if (deleteFujian<0) {
            throw new RuntimeException("删除附件失败");
        }

        return true;
    }

}
